// cQPSelectTasksPage.cpp : implementation file
//

#include "stdafx.h"
#include "QPMig.h"
#include "cQPSelectTasksItemsPage.h"
#include "helper.h"
#include "cNotesFolderInfo.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CQPMigApp theApp;

/////////////////////////////////////////////////////////////////////////////
// cQPSelectTasksPage property page

IMPLEMENT_DYNCREATE(cQPSelectTasksPage, CPropertyPageEx)

cQPSelectTasksPage::cQPSelectTasksPage() : CPropertyPageEx(cQPSelectTasksPage::IDD,0, IDS_QPSELECTCALENDARITEMSHEADERTITLE, IDS_QPSELECTITEMSHEADERSUBTITLE)
{
	//{{AFX_DATA_INIT(cQPSelectTasksPage)
	m_bBeenHere=FALSE;
	//}}AFX_DATA_INIT
}

cQPSelectTasksPage::~cQPSelectTasksPage()
{
}

void cQPSelectTasksPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPageEx::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(cQPSelectTasksPage)
	DDX_Control(pDX, IDC_LIST1, m_lbItems);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(cQPSelectTasksPage, CPropertyPageEx)
	//{{AFX_MSG_MAP(cQPSelectTasksPage)
	ON_LBN_DBLCLK(IDC_LIST1, OnDblclkList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// cQPSelectTasksPage message handlers

BOOL cQPSelectTasksPage::OnSetActive() 
{
	CPropertySheet* psheet = (CPropertySheet*) GetParent();   
	psheet->SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT);
	if(m_bBeenHere)
		{
			return CPropertyPageEx::OnSetActive();
		}
	m_lbItems.ResetContent();

	m_bBeenHere=TRUE;
	
	for(int i=0;i<=theApp.stControl.pdb->cobjNotesFolders.GetUpperBound();i++)
		{
			cNotesFolderInfo *pFolderInfo=(cNotesFolderInfo *)theApp.stControl.pdb->cobjNotesFolders.GetAt(i);
			if(pFolderInfo)
				{
					if(pFolderInfo->m_wType==NODEFFOLDER || pFolderInfo->m_wType==TASKFOLDER)
						{
							int id=m_lbItems.AddString(pFolderInfo->m_strFolderDisplayName);
							if(LB_ERR!=id)
								{
									m_lbItems.SetItemDataPtr(id,pFolderInfo);
									if(pFolderInfo->m_wType==TASKFOLDER && pFolderInfo->b_Transfer)
										m_lbItems.SetSel(id);
								}
						}


				}
			
		}
	return CPropertyPageEx::OnSetActive();
	
}


LRESULT cQPSelectTasksPage::OnWizardNext() 
{

	UpdateData(TRUE);
	DWORD dwErrCode=0;
	for(int i=0;i<m_lbItems.GetCount();i++)
		{
			if(m_lbItems.GetSel(i))
				{
					cNotesFolderInfo *pFolderInfo=(cNotesFolderInfo *)m_lbItems.GetItemDataPtr(i);
					if(pFolderInfo)
						{
							pFolderInfo->b_Transfer=TRUE;
							pFolderInfo->m_wType=TASKFOLDER;

						}
				};
		}

	
	return CPropertyPageEx::OnWizardNext();
}



void cQPSelectTasksPage::OnDblclkList1() 
{
	int nPage;
	CPropertySheet* psheet = (CPropertySheet*) GetParent();   
	if(psheet)
		{
			nPage=psheet->GetActiveIndex();
			if(OnWizardNext()>=0)
				psheet->SetActivePage(nPage+1);
		}
	
}
